class Solution(object):
    @classmethod
    def findMedianSortedArrays(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: float
        """
        len1 = len(nums1)
        len2 = len(nums2)

        # 将两个有序列表合并为一个有序列表
        numA = ''
        numB = ''

        ans = []

        # 赋初值
        if len1 > 0:
            numA = nums1[0]
        if len2 > 0:
            numB = nums2[0]

        # 两个分别的下标
        indexA = indexB = 0
        for i in range((len1 + len2)):
            # 两个都是空，结束
            if numA == '' and numB == '':
                break
            # 此时nums1为空，则直接全部填入到nums2，结束
            elif numA == '':
                for j in range(indexB, len2):
                    ans.append(nums2[j])
                break
            # 同理
            elif numB == '':
                for j in range(indexA, len1):
                    ans.append(nums1[j])
                break
            # 此时两个值都有，将小的填进去，大的保留继续作比较
            elif numA <= numB:
                ans.append(numA)
                if indexA+1 < len1:
                    indexA += 1
                    numA = nums1[indexA]
                else:
                    numA = ''
            elif numB < numA:
                ans.append(numB)
                if indexB+1 < len2:
                    indexB += 1
                    numB = nums2[indexB]
                else:
                    numB = ''
        # print(ans)
        if (len1 + len2)%2==0:
            return (ans[(len1+len2)//2] + ans[(len1+len2)//2-1])/2
        else:
            return ans[(len1+len2)//2 ]  


if __name__ == '__main__':
    ans = Solution()
    print(ans.findMedianSortedArrays([1,2], [3,4]))
